﻿using System;
using System.Timers;
using RSSReader.Properties;

namespace RSSReader.classesCustom
{
    public class DataHandlerTimer
    {
        private Timer testTimer;
        private DataHandler dataHandler;

        public DataHandlerTimer()
            : this(new DataHandler())
        {
        }

        public DataHandlerTimer(DataHandler dh)
        {
            this.dataHandler = dh;
            dataHandler.loadXMLArticles();
            //todo: get timer settings from config file
            testTimer = new System.Timers.Timer(Settings.Default.RepeatRssFeedReadIn); //  5 minute = 5*60*(1000 miliseconds)
            testTimer.Elapsed += new ElapsedEventHandler(OnTimerElapsed);
            
            testTimer.Enabled = true;
            testTimer.AutoReset = true;
        }

        private void OnTimerElapsed(object source, ElapsedEventArgs e)
        {
            dataHandler.loadXMLArticles();
            //Todo: send read notification to log
            Console.WriteLine("timer event activated !");
        }
                
    }
}